/**
 * @Author 孤风雪影
 * @Email gitee.com/efairy520
 * @Date 2024/4/17 1:12
 * @Version 1.0
 */
public class leecode_11 {
    /**
     * 11. 盛最多水的容器
     * 输入：[1,8,6,2,5,4,8,3,7]
     * 输出：49
     *
     * @param args
     */
    public static void main(String[] args) {
        leecode_11 leecode11 = new leecode_11();
        int[] height = {1, 8, 6, 2, 5, 4, 8, 3, 7};
        int i = leecode11.maxArea(height);
        System.out.println("i = " + i);
    }

    public int maxArea(int[] height) {
        //双指针
        int left = 0;
        int right = height.length - 1;
        int result = 0;
        while (left < right) {
            result = Math.max(result, (right - left) * Math.min(height[left], height[right]));
            //一个水桶能装多少水，取决于短板，短板越长，水越多
            if (height[left] < height[right]) {
                left++;
            } else {
                right--;
            }
        }
        return result;
    }
}
